import {getRequest, postRequest} from "@/utils/request.js";

/**
 * 发布视频请求
 * @param catId
 * @param md5
 * @param title
 * @param introduce
 * @param format
 * @param url
 * @param coverPicture
 * @param size
 * @param duration
 * @param publishTime
 * @returns {Promise<unknown>}
 */
export async function publishVideo(catId, md5, title, introduce, format, url, coverPicture, size, duration, publishTime = new Date()) {
    const params = {
        catId,md5, title, introduce, format, url, coverPicture, size, duration, publishTime
    };
    try {
        return await postRequest("/heaven-server/video/auth/publish", params);
    } catch (e) {
        console.log(e);
        return {code: -1, msg: `发布视频失败-${e.message}`}
    }
}

/**
 * 获取视频信息
 * @param videoId
 * @returns {Promise<unknown>}
 */
export async function getVideo(videoId) {
    try {
        return await getRequest('/heaven-server/video/get', {videoId});
    } catch (e) {
        console.log(e);
        return {code: -1, msg: `获取视频失败-${e.message}`}
    }
}

/**
 * 获取视频分类树
 * @returns {Promise<unknown>}
 */
export async function listCategoryTree() {
    try {
        return await getRequest('/heaven-server/video/category/list-tree');
    } catch (e) {
        console.log(e);
        return {code: -1, msg: `获取视频分类树失败-${e.message}`}
    }
}

export async function recommendVideo(){
    try {
        return await getRequest('/heaven-server/video/recommend');
    } catch (e) {
        console.log(e);
        return {code: -1, msg: `获取推荐视频失败-${e.message}`}
    }
}

export async function listOwnVideos(page = 1, size = 6) {
    try {
        return await getRequest('/heaven-server/video/auth/list--own-videos', {page, size});
    } catch (e) {
        console.log(e);
        return {code: -1, msg: `获取视频稿件列表失败-${e.message}`}
    }
}

export async function handleLikeRequest(videoId) {
    try {
        return await getRequest('/heaven-server/video/auth/handle-like', {videoId});
    } catch (e) {
        console.log(e);
        return {code: -1, msg: `点赞失败-${e.message}`}
    }
}

export async function handlePlayCount(videoId, type, token) {
    try {
        return await postRequest('/heaven-server/video/handle-playCount', {videoId, type, token});
    } catch (e) {
        console.log(e);
        return {code: -1, msg: `播放量增加失败-${e.message}`}
    }
}